Added some more logic for dynamically loading pages