improve pattern generation