fixed test and refactor