Fix to cleanup routine