Code merging and rewriting