fix weight function