extracted some logic from controllers to services