Database Rewrite

Reorganized the interface for the SQLite database.