added inversion option to replicate