Rewrite with a more modular structure.