fixed traverse function