moved function into model