added comments
refactored generator code