Refactors complex code