use ptrdiff_t cast in a few key places in an attempt to avoid warnings