a little mod to the original code by  Paul Martini (OSU)