cleaned up generator, fixed some NULL segfaults, cleaned up R interface, refitted main to example