Refactored PAIRS in js