Fix for part one of GitHub issue #118
Part two of fix to GitHub issue #118 -- need to test thoroughly though.