Fixed calling on_connect() so that it is called only once; fixes #31