Code climate refactoring

Refactoring to reduce duplication and complexity.
Surrounding space missing for operator '='.