Finished generate function