Refactoring build, save and restore for gaz.