Fixed issue with PROTECT/UNPROTECT