Factoring out path generation function.