Refactored a lot of the String matches and replaceAll methods to use precompiled patterns to save resources.