debugged variable inversion (!)