implement gengt()
add out of memory check