Bug fix by Slembcke, and other minor stuff