1. Moved a bunch of stuff to config files
2. Had each function create its own session, and wrapped the inserts in try/catch to avoid bugs when a flush() fails.