Cleanup error handling.
Implement more traits for more places; also, get rid of the generate() method.