Major changes and clean up to allow new database code.