some refactoring, simple count metric implemented but not yet executed due to memory leaks