first attempt at Problem 4