Step 4 code, not yet debugged