Fixed an issue with wrong thread getting used.