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