added server termination logic