script to calculate weight and sort