Fix a few small bugs.
Some basic tests.