Refactored command garbage collection