moved helper to application_controller.rb, cleaned up and commented code; fixes #470