refactor and fix bags