generate method refactored