Moved logic to controller