performance optimisations: profiling with xdebug, made string buffer, other improvements