terminate properly