updated the methodology to find the top view controller to support multiple types of root view controllers