Found the problem with the non mixing temperatures. The atoms were not being sorted correctly. I have now changed the code to copy the complete array after a sort, not just the pointer.