Nearly final version of rewrite of path-related logic.