Implements part A of #22. Part B is yet to come.