Moved flag assignment before their execution