write using substack's traverse module