Fixed bug with closing the connection to the db