reoganize code into the runCommand method

Change-Id: I21c526de62edbab4a5af298f3dea02665015eac4