Refactored and reorganized.