Fix a bug in weight computing.