More refactoring of processCommand method