CHG move code to make things clearer.