Alternative method for calculating path length