optimizing running time