heavy refactoring, statistics work