Implemented large part of ProgramFactory