fixed shutdown issues with multiple threads