more robust ended flags