General rewrite to support more things.