got rid of weird inversions, but still lots of duplicates to be dealt with at a later date