Fix generation bugs