Further refactor CommandFactory as recommended by Scrutinizer