reorganizing code for better clarity