Re-orged some sort code