Refactor remove_obsolete() into smaller methods