Put $th declaration inside traverse