added bounds checks