Generation cleanup

This is a set of changes to simplify the page clean/dirty code, and fix a few bugs along the way.

It's not ready to pull, I'm creating the pull request to make it easier to review.