Added a ton of tests, and finally fixed a bug.