private static Operation interpretNextCommand(Scanner scanner) throws FactoryException {
        String command = scanner.next();

        if (command.equals("print")) {

            System.out.println(image.toString());

        } else if (command.equals("printsaved")) {

            if (saved.size() == 0)
                System.out.println("NO SAVED IMAGES");
            else
                for (AsciiImage image : saved) {
                    System.out.println(image.toString());
                }

        } else if (command.equals("undo")) {

            if (stack.empty())
                System.out.println("STACK EMPTY");
            else
                image = stack.pop();

        } else {
            Factory commandFactory = factoryMap.get(command);

            if (commandFactory == null)
                throw new IllegalArgumentException("UNKNOWN COMMAND");
            else
                return commandFactory.create(scanner);
        }

        return null;
    }