Generalize path prefix code