improving the algorithm to avoid a specific and unlikely collision case