final refactor