Fixed some small bugs involving uninitialized values / double frees.