condensed to utilize Brett's much better code