Fixed up memory offsets; turned most magic numbers into constants