Fix generate

Fix bug in generate, closes #166