refactor; fix test case