Refactorings to reduce code complexity