refactored based off of exercism feedback