added connection timeout
fixed unit tests and resolved bugs