write DV code in a more efficient way