Updated submission of working code. Tested ok.