Moved close db to separate function