Fixed bugs in generation