Added close for connections that timed out, simplified loop exiting a bit