fix stop condition bugs and both master and slave are done