Fix startup issue and mainthread issue