added check to make sure pages exist before swapping out tmp table