detect run mode more carefully