Test mode detection. Fix a few tests.