Refactoring some of the complexity of the renderPage method into smaller private methods.
Bugfix - should have taken account of the page.