Fix bug in assigning scope number.