Factor traversal into Program class.