implemented get shortest loop