added weighted function