Fix bugs.  All tests pass.

Change-Id: I7bd32333498051a63e3f975f93e48bef41a3b6e4