Adds some unit test, refactors Haztory based on the tests