Moved pagination to the publish function