Lots of silly bug fixes