code posted to my blog hmkcode.com