Fixing js error in conditional exit