Restructuring code to be more modular