logic errors, and better alloc, realloc macros