Rewrite and speed-up