Made code slightly more DRY