Altering some code to make it more DRY