Finished exercise 2.3

Some duplication in code.