Small improvements

Formatted the code and added a closure to avoid recreating all the regexes for every node.