Changed int variables to NSInteger variables to aid 64 bit compatibility.