a bunch of changes

A bunch of useful changes - I can split these into separate pull requests if requested.