Rewriting algorithm | ScratchStats