Corrected bug with histogram dump. Continued refactoring