Simplify functionality, and convert listpages() to a generator