Added stop button and flag variable on c++ side to terminate early