Fix race in checking main completed (wrong if placement)