reorganizing code to avoid cycle dependency