Fixed the final page logic.