Fixed a bug in path-counting function.