Implemented generation algorithm. Untested.