fixed bug in pagination code