Moved the main program to a function to be callable by tests

- Provide also a function should_run() to stop the function whenether
you want