add test and refactor utils function