updated main.cpp to use traverse