Rewrite to be more extensible.