code for r04, scoping