changing connection logic to polling