Fix flag display logic, spelling error, and make code easier to understand