more refactoring. Use early exits instead of really complex logic.