Updates to prevent crazy string reallocation

- Moved charmap to outer scope
- Wrapped plugin in closure
- Created regexp that matches all chars in the charmap
- Used regexps to build the new string in order to prevent excessive memory churn