Lots of little bug fixes