added -g/--generate and fixed a bug or two