Added termination condition