Restructured code so that no memory is allocated in the C code. Now garbage
collection works.