add --debug command-line option, fixes for generator and optimizer