changes to avoid cast or assignment of long to int, or narrowing conversions.  Compiles without warnings and works o 64-bit as well as 32-bit now