Version 2 of code from GMR