refactored code for week 4 technical blog