streamlined code a bit for octave(MATLAB)