Handle resource and cleanup.