added secondary sort while creating a weighted list