migrating logic from controller to services