redid problem 5 as functional