Switched from using a thread-based poll system to one that polls when
the window gains focus.
Also un-auto-formatted the code