Lots of misc. fixes