Updated code with new functionality related to
1) pagination