Check for terminal condition