moved functions to model