Refactoring

Changed where n_generate is applied, rewrote 'stitching' function