Fix infinite thread spawn