refactor and add unit test
fix typo