Restructure and algorithm work