use bottom-up function to handle traversal