Fixed loading of metrics from database, small refactorings.
Refactoring.