Minor modifications to reduce extra code and terminate the process
properly