Fixed threadding errors from issue #37

Fixes issues #37