Refactoring

Refactor database classes (work in progress)