Fix a potential js error because of wrong logic