better handling of pagination