Fixed error on computing path length.

Also enabled protection against cheating.