Implementation of bag template.