diff --git a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
index 5e16abf8011c8e2d7467d601950e0847f1b76208..5729da8e806eecafb34d9f837a78c0e94e5fff95 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
@@ -54,6 +54,7 @@ static jmethodID R_FindNamespaceMethodID;
 static jmethodID Rf_GetOption1MethodID;
 static jmethodID Rf_gsetVarMethodID;
 static jmethodID Rf_inheritsMethodID;
+static jmethodID Rf_lengthgetsMethodID;
 static jmethodID CADR_MethodID;
 static jmethodID TAG_MethodID;
 static jmethodID PRINTNAME_MethodID;
@@ -118,6 +119,7 @@ void init_internals(JNIEnv *env) {
 	Rf_GetOption1MethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_GetOption1", "(Ljava/lang/Object;)Ljava/lang/Object;", 1);
 	Rf_gsetVarMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_gsetVar", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V", 1);
 	Rf_inheritsMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_inherits", "(Ljava/lang/Object;Ljava/lang/String;)I", 1);
+	Rf_lengthgetsMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_lengthgets", "(Ljava/lang/Object;I)Ljava/lang/Object;", 1);
 //	Rf_rPsortMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_rPsort", "(Lcom/oracle/truffle/r/runtime/data/RDoubleVector;II)", 1);
 //	Rf_iPsortMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_iPsort", "(Lcom/oracle/truffle/r/runtime/data/RIntVector;II)", 1);
     CADR_MethodID = checkGetMethodID(env, CallRFFIHelperClass, "CADR", "(Ljava/lang/Object;)Ljava/lang/Object;", 1);
@@ -395,7 +397,7 @@ SEXP Rf_mkCharCE(const char *x, cetype_t y) {
 }
 
 SEXP Rf_mkCharLen(const char *x, int y) {
-	return unimplemented("Rf_mkCharLen");
+	return Rf_mkCharLenCE(x, y, CE_NATIVE);
 }
 
 SEXP Rf_mkCharLenCE(const char *x, int len, cetype_t enc) {
@@ -593,7 +595,11 @@ SEXP R_FindNamespace(SEXP info) {
 }
 
 SEXP Rf_lengthgets(SEXP x, R_len_t y) {
-	return unimplemented("Rf_lengthgets");
+	TRACE("%s(%p)", x);
+	JNIEnv *thisenv = getEnv();
+	invalidateCopiedObject(thisenv, x);
+	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_lengthgetsMethodID, x, y);
+	return checkRef(thisenv, result);
 }
 
 SEXP Rf_xlengthgets(SEXP x, R_xlen_t y) {
@@ -1186,6 +1192,7 @@ const char *R_CHAR(SEXP string) {
 	char *copyChars = malloc(len + 1);
 	memcpy(copyChars, stringChars, len);
 	copyChars[len] = 0;
+	TRACE("%s(%s)", copyChars);
 	return copyChars;
 }
 
diff --git a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
index d485f0456dcce097540c696c6e98100e86e04057..9953c78ba72e1561b09c210d31ff19e0d29f8e03 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -93,36 +93,58 @@ jmp_buf *getErrorJmpBuf() {
 	return callErrorJmpBuf;
 }
 
+void releaseCopiedVector(JNIEnv *env, CopiedVector cv) {
+    if (cv.obj != NULL) {
+	switch (cv.type) {
+	    case INTSXP: case LGLSXP: {
+		    jintArray intArray = (jintArray) cv.jArray;
+		    (*env)->ReleaseIntArrayElements(env, intArray, (jint *)cv.data, 0);
+		    break;
+	    }
+
+	    case REALSXP: {
+		    jdoubleArray doubleArray = (jdoubleArray) cv.jArray;
+		    (*env)->ReleaseDoubleArrayElements(env, doubleArray, (jdouble *)cv.data, 0);
+		    break;
+
+	    }
+
+	    case RAWSXP: {
+		    jbyteArray byteArray = (jbyteArray) cv.jArray;
+		    (*env)->ReleaseByteArrayElements(env, byteArray, (jbyte *)cv.data, 0);
+		    break;
+
+	    }
+	    default:
+		fatalError("copiedVector type");
+	}
+    }
+}
+
 void callExit(JNIEnv *env) {
 //	printf("callExit\n");
 	int i;
 	for (i = 0; i < copiedVectorsIndex; i++) {
-		CopiedVector cv = copiedVectors[i];
-		switch (cv.type) {
-		    case INTSXP: case LGLSXP: {
-			    jintArray intArray = (jintArray) cv.jArray;
-			    (*env)->ReleaseIntArrayElements(env, intArray, (jint *)cv.data, 0);
-			    break;
-		    }
-
-		    case REALSXP: {
-			    jdoubleArray doubleArray = (jdoubleArray) cv.jArray;
-			    (*env)->ReleaseDoubleArrayElements(env, doubleArray, (jdouble *)cv.data, 0);
-			    break;
-
-		    }
-
-		    case RAWSXP: {
-			    jbyteArray byteArray = (jbyteArray) cv.jArray;
-			    (*env)->ReleaseByteArrayElements(env, byteArray, (jbyte *)cv.data, 0);
-			    break;
+		releaseCopiedVector(env, copiedVectors[i]);
+	}
+	copiedVectorsIndex = 0;
+}
 
-		    }
-		    default:
-		    	fatalError("copiedVector type");
+void invalidateCopiedObject(JNIEnv *env, SEXP oldObj) {
+	int i;
+	for (i = 0; i < copiedVectorsIndex; i++) {
+		CopiedVector cv = copiedVectors[i];
+		if ((*env)->IsSameObject(env, cv.obj, oldObj)) {
+#if TRACE_COPIES
+			printf("invalidateCopiedObject(%p): found\n", x);
+#endif
+			releaseCopiedVector(env, cv);
+			copiedVectors[i].obj = NULL;
 		}
 	}
-	copiedVectorsIndex = 0;
+#if TRACE_COPIES
+	printf("invalidateCopiedObject(%p): not found\n", x);
+#endif
 }
 
 void *findCopiedObject(JNIEnv *env, SEXP x) {
diff --git a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
index 9cd0cd4c25d55ef437d63b2ff1eec883f75b88be..a31fd8b65572e53996f2d90409c0951fecf5214f 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
+++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,6 +65,7 @@ jmp_buf *getErrorJmpBuf();
 void *findCopiedObject(JNIEnv *env, SEXP x);
 // add a new object to the internal rep cache
 void addCopiedObject(JNIEnv *env, SEXP x, SEXPTYPE type, void *jArray, void *data);
+void invalidateCopiedObject(JNIEnv *env, SEXP oldObj);
 
 void init_rmath(JNIEnv *env);
 void init_variables(JNIEnv *env, jobjectArray initialValues);
diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java
index e9ea6ccea46fbc3ab821dd2c489f13537be5fa94..80bae859a9d6066ebcb464f68bbbdd39b3f5b5e4 100644
--- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java
+++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/CallRFFIHelper.java
@@ -232,10 +232,6 @@ public class CallRFFIHelper {
     public static void Rf_setAttrib(Object obj, Object name, Object val) {
         if (obj instanceof RAttributable) {
             RAttributable attrObj = (RAttributable) obj;
-            RAttributes attrs = attrObj.getAttributes();
-            if (attrs == null) {
-                attrs = attrObj.initAttributes();
-            }
             String nameAsString;
             if (name instanceof RSymbol) {
                 nameAsString = ((RSymbol) name).getName();
@@ -244,7 +240,11 @@ public class CallRFFIHelper {
                 assert nameAsString != null;
             }
             nameAsString = nameAsString.intern();
-            attrs.put(nameAsString, val);
+            if ("class" == nameAsString) {
+                attrObj.initAttributes().put(nameAsString, val);
+            } else {
+                attrObj.setAttr(nameAsString, val);
+            }
         }
     }
 
@@ -279,6 +279,11 @@ public class CallRFFIHelper {
         return 0;
     }
 
+    public static Object Rf_lengthgets(Object x, int newSize) {
+        RAbstractVector vec = (RAbstractVector) RRuntime.asAbstractVector(x);
+        return vec.resize(newSize);
+    }
+
     public static int Rf_isString(Object x) {
         return RRuntime.checkType(x, RType.Character) ? 1 : 0;
     }