added clear method and moved extra line printing for traversal to after recursive method call