added some pointer arithmetic optimization