Move some common character-shuffling tasks to a trait and make them more robust.