Fixed if statement to evaluate values, not indices