added function to flip gradient vectors