move the pattern building outside of the clouser