Fix for 32bit integer

The previous pull request was not working on 32bit environments.
I had to do some workarounds to make it work on both 32bit and 64bit.