Refactoring of generator.
Preparations for tests.