Removed the declaration of variables in advance.
Change the 'case' to 'action' to increase clarity.
The function 'format' is replaced by parameters.