Added a termination check