moving generate code to library format