some algorithm design