added bounds check