Properly handle connection failure from condition (ugly)
Added basic tests