Some of this code was sent by Howard Miller, but I rewrote most of it to make it shorter and to fit in better with current code.