changed total pages to variable