Refactor code defining private classes and clean factories