Fix for GitHub issue #122 and other fixes