Fixed warnings and memory allocation issue that could lead to bad memory.