Fixes to a bunch of bugs.