Moove some code from controllers to services