Wrote an alternate version to question 2