Improve readability of executeCommand() function