initial pattern generation and other fixes