adding some error checking for connecting to database