Added asserts to each malloc and realloc