fix test and refactor