Use context manager for both connection and cursor in db initial setup.
Also some tiny refactoring for module consistency.