Fix ordering issue when generating file