moved some function to model