Made ln more efficient in checking for loops.