some fixes, added process exit management - added db closure