changes to try connection until timeout it completed
and adds debug option