use cardinality constraints throughout for a shorter and more efficient version