Replace list of checks with loop. Fix lvalue casts.