added cleanup for missing terminals