Gave a more robust solution to 4 using the prof's and the book's hint