Fixed lengthOfPath producing wrong results

Included comments to explain the error