turned the routine into a function