some more improvements
works also in buffered mode