some refactoring and implement threaded histogram