added terminate conditions