Thread get segv fix

This pull request takes care of fixing issue #19 and adding unit tests to check for regression (mainly by spawning multiple threads)