optimizing algorithm 2
optimizing algorithm 2