more fixes
- use tokenizer and strcat instead of doing some dirty tricks. code less efficient but not on the hot path anyway. hopefully code is easier to understand and maintain.
- set stdout to line buffering. avoids having to call fflush() manually (or forgetting to do so...)