refactored controller to eliminate repitition