Fix pyflakes errors
Refactor polling