Refactor for registry and resource cleanup.