updated to work in both 64 and 32 bit mode