completed solution for finalprob5, v2 was used to test refactored code