Fixed attempted cleanup on undefined last document.