Fixed second error, a variable being accessed after being deallocated.