added support for direction inversion