Rewrite the redirecting. Some general cleanups.