refactored controller.rb