first attempt at problem 6