fixed: database connection after checking for erorr, changed: formatting