Updated algorithms to deal with paths