Logic inversion bug fix