Moved logic to model