reorganize code of the bagger page