Smoothed out Matlab code