more consistent boundary check