cleaned gen up more, fixed more NULL bugs, moved value checking to C, added R gen demo