Added typecast to int64_t before reading, changed order of stop condition test to take advantage of C short circuit.