Added timeout option and socket closing verification