Refactor a bit to reduce complexity.