Added loop detector and BBorder calcualtor