Fix for stopping other python apps

and some code clean up