implemented coordinator main loop and revised some of code