Improve code quality and coverage

Improve code quality and coverage, add database classes, re-factor ambiguous methods.