improved bounds check