porting pagination snippet from old blog