Fix uses of ulong where 32-bit integers are expected