Clean up command processing code a bit.