Added exception handling to db inserts