Converted closures in Module.php to factories

Converted closures in Module.php to factories