add debug to flag switching, correct var name