Changed Page<T> BuildPageQuery and Count logic to make more general.

Did not seem to be working; now passes all tests, including new tests
with DISTINCT.