Big bug fixes

There were lots of bugs in the first release. We don't do any good
programming in the middle of the night... These bugs should now be
fixed.