add recursive save function