fix weight calculation, uninitialized value