Move more functions into model