jh - merged Kenneth's code