Added logic that tries to minimize the dipole moment