Improve path selection in generation

+ minor fixes