new version with fixed bug on connection