Added new method and typo fix for closing db
Major bug fixes found from unit tests