updating with Ralphs new code