modified to top-down