bug fixed, stopping criteria included