Created a traverse function