almost working but stops after writing 3 blocks to memory