Lots and lots of bug fixes