A working version with weights