Lots of minor fixes