Moving logic to model