added page calculation code