Refactored d_controller.rb