Added weight variable and Count() function