More refactoring, fewer branches.  #138