Refactored into several smaller files