updated modified bagging routine