End refactor