Refactored generate a bit.