Making logic around pagination dryer