Modified cleanup routine