Added image inversion and reduced loop time