Refactored and fixed page navigation.