refactor and substitute select for delete_if