fix for timeout failures on slow connections. code cleanup.