added stop conditions