implements save function