Refactor iteration in controller