New code for generating pairs; needs cleanup