Refactoring reducing complexity