Fix endless loop

- Add buffer trimming
- Remove verbosity in mutex