added find loop start algorithm