More fixes

Hi, we fixed more memory related issues. Feel free to merge.