Added support for executing commands in the main thread.