Fixed some memory issues, also had a improvement on the memory allocation stuff.