Lots of misc fixes