refactored the exec_command code so it will be more stabile.