full code with weights