Added error handling and used connect fucntion in db.py