rewrite it, using c-style data structure. a lot faster.