Refactor A1_detect