Remove isrunning() and move detection code into main()