Refactoring polling code into an object