Refactor previous patch to use std::remove_if