if min >= max then they are swapped