implement generate; fix issue #6