Refactor some page preview code.