Move the poll function into its own function