rearrange firmware->algorithm logic
fix an include