Cleaned up the code of CommandHandler a bit.