Factored out the process killing logic into a separate method for readability