A Class of Algorithms for General Instrumental Variable Models