added inversion option. code organized.