Completed pagination(). Refactoring may be required
done refactoring pagination(). Also fixed some bugs with it