move detect into compile