Restructuring code into controller classes