Refactored into more modular structure.