fixed calcPairs and added more test code