Fixed some problems with the flagsRemaining code.