Misc cleanup

The important fixes from pull request #865