moved functions from controller to a service