added a couple of database disconnection and fixed indentation