Updated generator with error handling, fixes #93