More Tests, optimizations, refactors and less use of regular expressions