Fixing timeout logic