Fixed typo that failed unit test and simplify code