sorted set refactor