refactoring for part two of blog post