Huge improvement to segment alignment algorithm