Fix a wrong comparison and saving a sorted set