Streamlined code and made more modular