moved logic to controller