adding timeout to detect cycles