ran some IntelliJ IDEA inspections on code

- removed superfluous String.format() calls
- replaced single character strings with chars
- replaced one regex with precompiled pattern
- replaced tail recursion with loop