Refactored to show intent of code in a more clear way