moved code from controller to service