refactor javascript step 4