Found some bugs but not the memory corruption. Still working on it.