moved logic to model