correction in break calculation and better event handling