Merge pull request #440 from shaitan/master

Core: stops threads before joining them in case we got some error while ...