Make z_paths code more generic