restructuring code for better maintenance