Various bug fixes and enhancements

Here are the various bugfixes and enhancements I have created over the last week or so.