Move save function out of model