rewrite common prefix code