Revert "Revert "Refactored bounds logic.""

This reverts commit 8023ec4791e64e6a8183928989deef9ce5f593f8.