fix boundary write bug