Refactored prune_objects slightly for readability