Fix bugs in bounds caching algorithm.