old code by Chris and Stan