Corrected 1D code