fixed bug with bag sorting