Use extract method to remove a bit of duplicated code