Major modification: Use CmdThread instead of Thread.