calculating the path