improved traversing with rec depth-first and rec depth-last