add autopaging directive
destroy elem
make code easier to read