add try catch to all potential exception points; change insert to update with upsert