Refactored code:
- minimized use of macros
- fixed some english grammar errors
- removed manual allocations in output buffer