Fixed small threading bug