Refactored into several files