Restructure friend research with function