Refactored bounds logic.