correct amount of paged items returned

fixed the bug that cause incorrect amount of paged results to be
returned.
fixed some indentation issues