bug fixed to balanced sampeling