Move factories from closures in Module.php to separate classes

- move factories from closures to classes
- fix some annotations
- various typo and CS fixes