Fixed bug where db-queries were not closed