Refactors duplication and complexity