Minor changes, added stopping rule