added check for if pages is null