BUG+FIX on the way: Each call to R's error() will cause potential memory leaks; destructors are not called automatically; must rewrite to C++ try-catch