Refactored object detection