Fixed a horrible memory leak and an assertion.