first working tree parser, pretty ugly implementation