Fix lots of bugs.