changed bounds check slightly