Moved logic from controllers to models