Fixed possible infinite loop when using Python 3 to merge pages