Reorganizing the code for assignment6