Wrote problem 4; seems to work!