Small changes to save function