Minor fix to end conditions