refactored from hm