HDAT: Refactored code and added more tests