renamed sample to sample for weighted sampling