Refactored hmlib