Added debug flag.
Fixed some realloc's which had incorrect sizes :(.