Misc fixes

This set of patches is available under the terms of the MIT license.