Added connection timeout and loss handling

Close #12