refactoring to reduce complexity.