More specific bounds checking, and tests.