Database: improved fetchPairs, added tests