Refactoring leaf into smaller modules