Finish recursive generate function