improved memory management for parser, no more seg faults