Move some function to model class