updated database functions to properly close cursor and db in all places