changes for easy management of DB connection

- db connection is now automatically closed unless there is a
transaction in progress