refactored using rails helpers
removed legacy code and renamed code with incorrect variable name