Refactored hgmd into seperate file