Just various source refactorings to reduce complexity