Slight refactoring to reduce complexity