Fix some bugs with the weight generation.