start refactoring of gen