Poll function finished. Needs some cleaning though (error-checking and edge cases)