Reversed if-statement due to undefined index