Fix a shitload of bugs.  Write a test to expose logical failure.