Lots of bug and performance fixes.