Move the detection logic to a separate package, and make it testable. Also make room for more detection mechanisms down the road if needed.