Simplify and make more modular