javascript refactor step 2