Fix refactor code and test