Because these three lines are repeated in three places, it would be beneficial to put them in a small function to avoid duplication and to allow the logic to be unit tested.