Partially revert 753e7074d84b5a2e8d3c3e92d25c54bb25ba477e and 12c680f9b1f1068099c3b19443d93d456690ac56 to simplify the code and to only remove GMs from the target list. (cherry picked from commit f9cfc202e90ded24fe0dcf5d06035d2aab2cf6af)