improved speed a bit and cleaned up buffer stream