Creating a termination function