Refactored polling function