Fix memory leak and small parser changes