rewrote the scattering code using in class examples