bag function

Calculates the bag