Added valid page checking, but not fully working