Various little changes, mostly fixing incorrect memory accesses