updated to extract functionality to model