rewrite toplevel