Implementations of problems two, three and four.