Fixed up a couple of type errors, but uncovered a bug somewhere...