Added all the command handling into the wrapper thread