Making sure connection to db is closed