remove_gates can now delete the last occurence of a given gate as well