optimization in serial code