Various fixes to make it work on 64 bit, introduced memory tracking as
well