fixed a bug in recursive traversal when doing layouting