re-organise the code of execute a command, make it modularized