make constraint functions be aware of swapped variables; added some tests