A few small fixes + Initializing "num_references" to 0. (I thought wma
initialized it.)  Also, fixed initialization of "next_p". Finally, added
some reinitialization code that was missing for a sql command.