fix boundary handling