Added typedefs and moved rule into function
Merge