made flag-checking nicer