Refactor and fix rendering of page controls