Fix the race condition between program stop and program status check and start.

- They should be using the same way to check if a program is running

Also some code refactoring to make the code cleaner
Plus a concurrency bug fix in getting program status for MR in workflow
Make sense. Fixed.