fixed a bug in building rewriting result