added weighted and k options to Diff cost function