Cleanup code 

Cleaned up code to improve readability, remove StringBuffers for compile-time finals/constants etc.

* simplified some if-else blocks
* removed redundant String[] generation
* introduced System.arraycopy which is much faster in copying arrays.
* replaced old-school for-loops by their for-each complements