Debug and change weight_function