Lots more small bug fixes