This piece of code shows up twice, can we make a small function for it?