Modified the code to stay DRY