improved core algorithm

Rewrote the core pairing algorithm. Now doubly efficient.