Refactor to reduce complexity