Refactoring excuteCommand() functions.