1.replace R_alloc with malloc/free for eCount to avoid garbage collection from R. 2. add boundary check for sampleIndx at c level to avoid potential segfault.