added code to prevent database from disconnecting