added weight function