Modified to use libgc to allocate memory