Weighted pairing

This takes over #5 as we can all work on it here. Please see that PR for reference.