moved some methods from controller to model