fix stackoverflow in main thread