streamlined code per Pete's suggestions