Added exit conditions