factor out pattern traversal
move code generation to class creation time