Isolated DB interactions somewhat crudely, I suppose.
bit cleaner, isolated DB code a bit better.  Deleted a lot of commented-out stuff.