various refactorings and tests
cherry-picked CommandExecutor changes from rewrite_commandcenter