Added assert.
Splitted path generation off into a separate function.