move get_top_period() function next to dosearch()