Move methods from controller to model so they can be reused elsewhere