Refactored block hit testing and selection mode code