working but not perfect. last buffer contains previous