refactor resource saving