Fix bug with $test_mode, it had to be declared earlier