fixed more memory leaks and fixed parsing bug