Added error handling when trying to connect to DB