Restructure logic