Beautified code in the rewrite function.