Added connection loop detection (fixes #17).