tree traversal problem, refer other's elegant code, good