Added a likely fix for issue #10 but uncovered another bug in the process.