general improvments and tests
improved buffer handling