Final version of breakpoint algorithm