change die to assure; fixed a case to realloc too early
formatting code style