Fixed threadding errors from issue #37