Fix errors when certain pages does not exist.

Also added some comments to clear up the logic.
Avoid tests from polluting the repository