Code cleanup

Moved more general code up, and more specific code down
Created regex matchers