Refactored into a more modular structure