lots of misc fixes