implemented stateful parser; removed memcpy, memmove and malloc/free calls