move detecting code to an async thread