optimise the code for generating pattern data: workable and correct version