refactor end