Code cleanup

Added a bunch of asserts to verify our behavior.  Also removed an unused
funciton.