working thread closer Stackoverflow 17554046