polling code cleanup. Still does not work