refactroing code in controller, to make it more clean based on mcv