More fixes

A medly of improvements used and code used in future pull requests. Each commit is independent of the others.