removed unncessary loopend check