Fixed bug where different sized pages caused script to crash