Unit tests for printHistory and some refactoring