Code climate refactoring

Refactoring to reduce duplication and complexity.
Line is too long. [93/80]