weight-sorting implemented