improved breaking logic