refactor code (move to hrlator.js)