[WIP] Slight refactor of database and fix for resume bug.

I'm probably going to continue working in this PR for now.  

At present, it cleans up some of the database interface and also fixes #65.