Bug fixes

So many that I've forgotten where I started...