So I have totally fixed the collisions. The problem definitely lies in the sorting of the arrays. I'm not sure what is wrong but I have implemented a work around. I am instead just sorting the atomID array, and then using that for collisions.