Solution to #4-7