final refactoring of Dominick and Andra's code for 5_refactoring