Final commit. Couldn't quite get the service end points to work, but the
logic is all there.