Updated with new loop conditions

Separated loop so that multithreaded commands can be issued within the
main loop.