Refactor code
Refactor the following code to make it cleaner, more readable and easier to maintain, without changing the behavior. Explain each improvement made (names, structure, duplication, complexity). Code: [CÓDIGO]. Language: [LINGUAGEM]. Maintain compatibility with [CONTEXTO/DEPENDÊNCIAS].