improving algorithm

not clear