BUG0007: Added error processing

- added error processing
- debug info is hidden by default and shown when error occurs
- some monor fixes of buffering and clean up