fixes #2: wrote a bunch of tests and then fixed stuff

the tests are maybe not as thorough as i'd want, but they already
revealed missing and broken functionality, so i think they're pretty
good.