Initial reimplementation of the UI element swap function.