changed the total weight algorithm