Cleanup, refactoring, and true pairing functions