A lot of misc fixes - should close #1006