working polling code